package inits

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"im/config"
	"im/global"
	"log"
)

func InitMysql() {
	var err error
	AppConf := config.AppConf.Mysql
	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", AppConf.User, AppConf.Password, AppConf.Host, AppConf.Port, AppConf.Database)
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("mysql 连接失败")
	}
	log.Println("mysql 连接成功")
}
